package com.csun.cmny.python;

import java.io.DataInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-04-08 13:16
 * @Description:
 */
public class CsunPythonMain {

    public static SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD HH:mm:ss");

    public static void main(String[] args) {

        if (args == null || args.length < 3) {
            System.out.println("Usage: python python.py input.json");
            return ;
        }

        StringBuilder sb = new StringBuilder();
        sb.append("====>                the runtime exec: ");
        sb.append(args[0]);
        sb.append(" ");
        sb.append(args[1]);
        sb.append(" ");
        sb.append(args[2]);
        System.out.println(sb.toString());

        try {

            Date start = new Date();
            System.out.println("====>          main csun python start: " + sdf.format(start));

            Process process = Runtime.getRuntime().exec(args);
            //InputStream is = process.getInputStream();
            //DataInputStream dis = new DataInputStream(is);
            //String line = "";
            //while ((line = dis.readLine()) != null) {
            //    System.out.println(line);
            //}
            process.waitFor();

            Date end = new Date();
            System.out.println("====>            main csun python end: " + sdf.format(end));

            System.out.println("====> main csun python time consuming: " + (end.getTime() - start.getTime()) + " millisecond");

        } catch (Exception e) {
            System.out.println("runtime error: " + e.getMessage());
        }

    }

}
